<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>异步请求</h1>
<div>
  <input type="button" value="get请求" @click="f1()">
  <input type="button" value="post请求" @click="f2()">
  <h2>{{info}}</h2>
</div>
<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
  let v = new Vue({
    el:"div",
    data:{
      info:""
    },
    methods:{
      f1:function () {
        //发出异步请求
        axios.get("helloAxios").then(function (response) {  //响应对象
          v.info = response.data//弹出相应的数据
        }).catch(function (err) {//错误对象
          alert(err)//弹出错误
        })
      },
      f2:function () {

      }
    }
  })
</script>
</body>
</html>